String.prototype.replaceAll  = function(s1,s2){   
return this.replace(new RegExp(s1,"gm"),s2);   
} 

Array.prototype.contains = function (elem) {
	for (var i = 0; i < this.length; i++) {
	if (this[i] == elem) {
		return true;
		}
	}
	return false;
}

Ext.override(Ext.form.Label, {
    getText : function(){
        return this.text || Ext.util.Format.htmlDecode(this.html);
    }
});

function showMessage(message,isError){
	var successDiv = document.getElementById("successDiv");
	var errorDiv = document.getElementById("errorDiv");
	if(isError==true){
		successDiv.innerHTML="";
		errorDiv.innerHTML = message;
	}else{
		errorDiv.innerHTML="";
		successDiv.innerHTML = message;
	}
}


function flashMessage(msg,compId,interval){
	Ext.MessageBox.show({msg:'<div vertical-align=middle>'+msg+'</div>',
						width:300,
						icon: Ext.window.MessageBox.INFO,
						animateTarget:compId});
	setTimeout(function(){
		Ext.MessageBox.hide();
	}, interval);
}

function getURLParameter(name) {
    return decodeURI(
      (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
    );
}

function loadJS(url){
  var js = document.createElement('script');

  js.type = "text/javascript";
  js.src = url;

  document.body.appendChild(js);

}


function columnWrap(val){
    return '<div style="white-space:normal !important;">'+ val +'</div>';
}

/**
 * Ext.data.Store extension to move a record within the data store
 * @param {Number} from Move record from
 * @param {Number} to Move record to
 */
Ext.data.Store.prototype.move = function(from, to){
    var r = this.getAt(from);
    this.data.removeAt(from);
    this.data.insert(to, r);
    this.fireEvent("refresh", this);
};

Ext.selection.CheckboxModel.prototype.onRowMouseDown = function(view, record, item, index, e) {
    //view.el.focus();
    var me = this,
        checker = e.getTarget('.' + Ext.baseCSSPrefix + 'grid-row-checker'),
        mode;
        
    if (!me.allowRightMouseSelection(e)) {
        return;
    }

    // checkOnly set, but we didn't click on a checker.
    if (me.checkOnly && !checker) {
        return;
    }

    if (checker) {
        mode = me.getSelectionMode();
        // dont change the mode if its single otherwise
        // we would get multiple selection
        if (mode !== 'SINGLE') {
            me.setSelectionMode('SIMPLE');
        }
        me.selectWithEvent(record, e);
        me.setSelectionMode(mode);
    } else {
        me.selectWithEvent(record, e);
    }
};